package com.xoms.admin.controller.springmvc;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.*;
import com.xoms.admin.controller.res.*;
import com.xoms.admin.controller.res.bean.*;
import com.xoms.admin.controller.springmvc.req.*;

/**
 * 商品减库存相关接口
 **/
@Controller
@RequestMapping(value = "/reduce", produces = "application/json")
public class SProReduceController {
	@Autowired
	com.xoms.admin.controller.ProReduceController proReduceController;

	/**
	 * 调拨-获取列表
	 **/
	@RequestMapping("/v1/getAllotList")
	@ResponseBody
	public ListResult<RProAllotBean> getAllotList(@Validated GetAllotListParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RProAllotBean> res = new ListResult<RProAllotBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proReduceController.getAllotList(param, request, response);
	}

	/**
	 * 调拨-详情列表
	 **/
	@RequestMapping("/v1/getAllotDetails")
	@ResponseBody
	public ListResult<RProAllotDetailBean> getAllotDetails(@Validated GetAllotDetailsParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RProAllotDetailBean> res = new ListResult<RProAllotDetailBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proReduceController.getAllotDetails(param, request, response);
	}

	/**
	 * 调拨-新建、编辑
	 **/
	@RequestMapping("/v1/editAllot")
	@ResponseBody
	public ObjectResult<RProAllotBean> editAllot(@Validated EditAllotParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<RProAllotBean> res = new ObjectResult<RProAllotBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proReduceController.editAllot(param, request, response);
	}

	/**
	 * 调拨-删除信息
	 **/
	@RequestMapping("/v1/delAllot")
	@ResponseBody
	public BaseResult delAllot(@Validated DelAllotParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		BaseResult res = new BaseResult();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proReduceController.delAllot(param, request, response);
	}

	/**
	 * 退货-获取列表
	 **/
	@RequestMapping("/v1/getPureBacks")
	@ResponseBody
	public ListResult<RProPureBackBean> getPureBacks(@Validated GetProPureBacksParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RProPureBackBean> res = new ListResult<RProPureBackBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proReduceController.getPureBacks(param, request, response);
	}

	/**
	 * 退货-获取详情
	 **/
	@RequestMapping("/v1/getPureBackDetails")
	@ResponseBody
	public ListResult<RProPureBackInfoBean> getPureBackDetails(@Validated GetPureBackDetailsParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RProPureBackInfoBean> res = new ListResult<RProPureBackInfoBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proReduceController.getPureBackDetails(param, request, response);
	}

	/**
	 * 退货-新建、编辑
	 **/
	@RequestMapping("/v1/editPureBack")
	@ResponseBody
	public ObjectResult<RProPureBackBean> editPureBack(@Validated EditPureBackParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<RProPureBackBean> res = new ObjectResult<RProPureBackBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proReduceController.editPureBack(param, request, response);
	}

	/**
	 * 退货-删除信息
	 **/
	@RequestMapping("/v1/delPureBack")
	@ResponseBody
	public BaseResult delPureBack(@Validated DelPureBackParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		BaseResult res = new BaseResult();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proReduceController.delPureBack(param, request, response);
	}

	/**
	 * 退货-提交审核
	 **/
	@RequestMapping("/v1/submitPureBack")
	@ResponseBody
	public BaseResult submitPureBack(@Validated SubPureBackParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		BaseResult res = new BaseResult();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proReduceController.submitPureBack(param, request, response);
	}

	/**
	 * 报损-获取列表
	 **/
	@RequestMapping("/v1/getBreakages")
	@ResponseBody
	public ListResult<RProBreakageBean> getBreakages(@Validated GetProBreakagesParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RProBreakageBean> res = new ListResult<RProBreakageBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proReduceController.getBreakages(param, request, response);
	}

	/**
	 * 报损-获取详情
	 **/
	@RequestMapping("/v1/getBreakageDetails")
	@ResponseBody
	public ListResult<RProBreakageInfoBean> getBreakageDetails(@Validated GetBreakageDetailsParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RProBreakageInfoBean> res = new ListResult<RProBreakageInfoBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proReduceController.getBreakageDetails(param, request, response);
	}

	/**
	 * 报损-新建、编辑
	 **/
	@RequestMapping("/v1/editBreakage")
	@ResponseBody
	public ObjectResult<RProBreakageBean> editBreakage(@Validated EditBreakageParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<RProBreakageBean> res = new ObjectResult<RProBreakageBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proReduceController.editBreakage(param, request, response);
	}

	/**
	 * 报损-删除信息
	 **/
	@RequestMapping("/v1/delBreakage")
	@ResponseBody
	public BaseResult delBreakage(@Validated DelBreakageParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		BaseResult res = new BaseResult();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proReduceController.delBreakage(param, request, response);
	}

	/**
	 * 报损-提交审核
	 **/
	@RequestMapping("/v1/submitBreakage")
	@ResponseBody
	public BaseResult submitBreakage(@Validated SubBreakageParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		BaseResult res = new BaseResult();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proReduceController.submitBreakage(param, request, response);
	}
}
